package com.yufei.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yufei.dao.User2Dao;
import com.yufei.domain.User2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
// 允许跨域
@CrossOrigin
public class User2Controller {
    @Autowired
    private User2Dao user2Dao;

    //查询所有
    @GetMapping("/user2")
    public List<User2> getAll() {
        return user2Dao.selectList(null);
    }

    // 分页查询
    @GetMapping("/page2/{current}")
    public IPage<User2> pageSelect2(@PathVariable Integer current) {
        IPage page = new Page(current, 12);
        user2Dao.selectPage(page, null);
        return page;
    }

    //新增人员
    @PostMapping("/add2")
    public String save2(@RequestBody User2 user) {
        user2Dao.insert(user);
        return "OK";
    }

    //删除接口
    @PostMapping("/delete2/{id}")
    public int delete2(@PathVariable Integer id) {
        return user2Dao.deleteById(id);
    }

    // 条件查询
    @GetMapping("/selectName2/{name}")
    public List selectName2(@PathVariable String name) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.like("name", name);
        return user2Dao.selectList(qw);
    }


}
